<?php
use Test\BaseTest;
include 'BaseTest.class.php';

class ApiTest extends BaseTest {
    const URL = 'http://api.maibei.com/';

    protected $_request = null;
    protected $_response = null;

    protected $_api = 'Index/index';

    public function __construct($testCases, $group='') {
        foreach ($testCases as $testCase) {
            if ($group && @$testCase['group'] != $group) {
                continue;
            }
            $method = $testCase['case'];
            $request = $testCase['request'];

            $this->$method($request);
        }
    }

    public function getUrl() {
        return self::URL . $this->_api;
    }

    public function __call($case, $arguments) {
        echo "\n", '测试用例: ' . $case , "\n";
        $this->setApi($case);
        $request = !empty($arguments[0]) ? $arguments[0] : [];
        $this->setRequest($request);

        $this->post();

        echo "Request  :\n    " . $this->getRequest(), "\n";
        echo "Response :\n    " . $this->getResponse(), "\n";
    }

}

$testCases = [
    /*[
        'case'    => 'Home/Index/index',
        'group'   => 'test',
        'request' => [
            "customer_id" => "123456789",
            'ak' => 'say',
            'bk' => 'hello',
            'ck' => 'world',
        ],
    ],
    [
        'case'  => 'Home/Customer/signUp',
        'request' => [
            'device_id' => 2222222222,
        ]
    ],
    [
        'case'  => 'Home/Customer/signIn',
        'request' => [
            'device_id' => 2222222222,
        ]
    ],
    [
        'case'  => 'Home/Customer/getInformation',
        'request' => [
            'customer_id' => 1,
        ]
    ],
    [
        'case'  => 'Home/Customer/saveInformation',
        'group' => 'saveInformation',
        'request' => [
            'customer_id' => 1,
            'verify_code' => 482765,
            'office_tel' => '40011112222',
            'mobile' => '15510089361'
        ]
    ],
    [
        'case'  => 'Home/Customer/saveIdCardInformation',
        'group' => 'saveIdCardInformation',
        'request' => [
            'customer_id' => 1,
            'real_name' => '赫宝匣1',
            'id_num' => 130531198805140615,
            'gender' => '男',
            'nation' => '汉',
            'birthday' => '1988年05月14日',
            'birthplace' => '河北邢台',
            'sign_organ' => '广宗公安局',
            'valid_period' => '2006.07.01--2016.07.01',
        ]
    ],
    [
        'case'  => 'Home/Merchant/getNearbyList',
        'group' => 'getNearbyList',
        'request' => [
            'customer_id' => 1,
            'lat' => '38.6518058510',
            'lng' => '104.0764250655',
            'category' => '0'
        ]
    ],
    [
        'case'  => 'Home/UserCenter/mine',
        'group' => 'mine',
        'request' => [
            'customer_id' => 1,
        ]
    ],
    [
        'case'  => 'Home/System/getLastSaveCallRecordTime',
        'group' => 'getLastSaveCallRecordTime',
        'request' => [
            'customer_id' => 1,
        ]
    ],
    [
        'case'  => 'Home/System/saveCallRecord',
        'group' => 'saveCallRecord',
        'request' => [
            'customer_id' => "1",
            'record_list' => [
                [
                    'phone_number' => '15510089361',
                    'in_out' => '1',
                    'duration_time' => '120',
                    'call_time' => '1468052075',
                ],
                [
                    'phone_number' => '15510089361',
                    'in_out' => 2,
                    'duration_time' => 400,
                    'call_time' => '1468052070',
                ],
            ],
        ]
    ],
    [
        'case' => 'Home/System/saveContacts',
        'group' => 'saveContacts',
        'request' => [
            'customer_id' => 1,
            "contact_list" => [
                [
                    "contact_name" => "休城",
                    "contact_phone" => "13212235674",
                    "group" => "家人",
                    "nick" => "皮皮",
                    "memo" => "备注"
                ],
                [
                    "contact_name" => "休城1",
                    "contact_phone" => "13212235673",
                    "group" => "家人",
                    "nick" => "皮皮1",
                    "memo" => ""
                ]
            ]
        ]
    ],
    [
        'case' => 'Home/UserCenter/getCertUploadStatus',
        'group' => 'getCertUploadStatus',
        'request' => [
            'customer_id' => 1,
        ]
    ],
    [
        'case' => 'Home/Customer/orderNextMonthRepay',
        'group' => 'orderNextMonthRepay',
        'request' => [
            'customer_id' => 1,
            'pay_pass' => '518E6C76CAF51EB410CAAB3C21DEF1B4B3C07401',
            'amount' => 10000,
        ]
    ],
    [
        'case' => 'Home/Customer/setPayPass',
        'group' => 'setPayPass',
        'request' => [
            'customer_id' => 1,
            'pay_pass' => '518E6C76CAF51EB410CAAB3C21DEF1B4B3C07401',
        ]
    ],
    [
        'case' => 'Home/UserCenter/bindBankCard',
        'group' => 'bindBandCard',
        'request' => [
            'customer_id' => 1,
            'card_user_name' => 'hebaoxia',
            'card_num' => '23232444444444',
            'reserved_mobile' => '15510089361',
            'verify_code' => 666666,
        ]
    ],
    [
        'case' => 'Home/Merchant/getSaleList',
        'group' => 'getSaleList',
        'request' => [
            'merchant_id' => 1,
        ]
    ],
    [
        'case' => 'Home/Merchant/withdraw',
        'group' => 'withdraw',
        'request' => [
            'merchant_id' => 1,
            'money' => 100
        ]
    ],*/
    [
        'case' => 'Home/UserCenter/getBillList',
        'group' => 'getBillList',
        'request' => [
            'customer_id' => 1,
            'offset' => 1,
            'length' => 2
        ]
    ],
    /*[
        'case' => 'Home/Customer/getVerifyCode',
        'group' => 'getVerifyCode',
        'request' => [
            'mobile' => '15510089361',
        ]
    ],*/
];

$opts  = getopt('', ['group:']);
$group = isset($opts['group']) ? $opts['group'] : false;

new ApiTest($testCases, $group);

